import Vue from 'vue'
import VueRouter from 'vue-router'
import { publicPath, routeMode } from '@/configs'
import { router } from '../../../bk-web-foundation/src/router'
import { constantRoutes } from './constant-routes'

Vue.use(VueRouter)

export function createRouter (routes = constantRoutes) {
  return new VueRouter({
    base: publicPath,
    mode: routeMode,
    scrollBehavior: () => ({
      y: 0
    }),
    routes
  })
}

// 解决首次路由跳转报错的 bug
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

export default router
